import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class MyFlowLayout extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MyFlowLayout frame = new MyFlowLayout();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MyFlowLayout() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JPanel panel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		panel.setBounds(10, 11, 421, 241);
		contentPane.add(panel);

		JButton btnButton = new JButton("Left");
		btnButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FlowLayout layout = (FlowLayout) ((JButton) e.getSource())
						.getParent().getLayout();
				layout.setAlignment(FlowLayout.LEFT);
			}
		});
		panel.add(btnButton);

		JButton btnButton_1 = new JButton("center");
		btnButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FlowLayout layout = (FlowLayout) ((JButton) e.getSource())
						.getParent().getLayout();
				layout.setAlignment(FlowLayout.CENTER);
			}
		});
		panel.add(btnButton_1);

		JButton btnButton_2 = new JButton("right");
		btnButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FlowLayout layout = (FlowLayout) ((JButton) e.getSource())
						.getParent().getLayout();
				layout.setAlignment(FlowLayout.RIGHT);
			}
		});
		panel.add(btnButton_2);
	}
}
